In this notebook, you will use Pypot and an Inverse Kinematics toolbox to make Torso's hands follow each other.
Your Torso has two arms, and you can use simple methods to get and set the position of each hand.
You will need a fully functionning torso, either IRL or in simulator (V-REP).
More info here.
To be more precise, we will tell the right hand to keep a constant distance with the moving left hand, like on the picture above :
The left arm will be compliant, so you can move it and watch the right arm following it.
We begin by configuring the robot, to fit our needs for the experiment.
Begin with some useful imports :
In [1]:
import time
import numpy as np
from pypot.creatures import PoppyTorso
Then, create your Pypot robot :
In [ ]:
poppy = PoppyTorso()
Initialize your robot positions to 0 :
In [5]:
for m in poppy.motors:
m.goto_position(0, 2)
The left arm must be compliant (so you can move it), and the right arm must be active
In [ ]:
# Left arm is compliant, right arm is active
for m in poppy.l_arm:
m.compliant = False
for m in poppy.r_arm:
m.compliant = False
# The torso itself must not be compliant
for m in poppy.torso:
m.compliant = False
To follow the left hand, the script will do the following steps :
That's exactly what we do in the hand_follow
function :
In [ ]:
def follow_hand(poppy, delta):
"""Tell the right hand to follow the left hand"""
right_arm_position = poppy.l_arm_chain.end_effector + delta
poppy.r_arm_chain.goto(right_arm_position, 0.5, wait=True)
Now, do this repeatedly in a loop :
In [ ]:
try:
while True:
follow_hand(poppy, target_delta)
time.sleep(delay_time)
# Close properly the object when finished
except KeyboardInterrupt:
poppy.close()
And you're done! Now you can move the left arm of the robot and see the right arm following.
The Inverse Kinematics functionnalities are provided by the IKPy library
The robot used here is part of the poppy-project, which also provides the motor-control library, Pypot.